<?php

namespace App\Models\Payment;

use App\Models\Payment\Platform\ChinaUms;
use App\Models\Payment\Platform\EbankPay;
use App\Models\Payment\Platform\FuiouAggregatePay;
use App\Models\Payment\Platform\FuiouPay;
use App\Models\Payment\Platform\UnionPay;

class PayCenter
{
    protected $driver;

    public function __construct(PaymentChannel $paymentChannel)
    {
        switch ($paymentChannel->category) {
            case PaymentChannel::CATEGORY_CHINAUMS:
                $this->driver = new ChinaUms($paymentChannel);
                break;
            case PaymentChannel::CATEGORY_FUIOUPAY:
                $this->driver = new FuiouPay($paymentChannel);
                break;
            case PaymentChannel::CATEGORY_FUIOUPAY_AGGREGATE:
                $this->driver = new FuiouAggregatePay($paymentChannel);
                break;
            case PaymentChannel::CATEGORY_EBANKPAY:
                $this->driver = new EbankPay($paymentChannel);
                break;
            default:
                $this->driver = new UnionPay($paymentChannel);
                break;
        }
    }

    public function toPay(string $tradeType, PaymentOrder $paymentOrder)
    {
        return $this->driver->toPay($tradeType, $paymentOrder);
    }

    public function toQuery(PaymentOrder $paymentOrder)
    {
        return $this->driver->toQuery($paymentOrder);
    }

    public function toRefund($refundOrder)
    {
        return $this->driver->toRefund($refundOrder);
    }

    public function toRefundT($amount, $paidCode)
    {
        return $this->driver->toRefundT($amount, $paidCode);
    }

    public function toClose(PaymentOrder $paymentOrder)
    {
        return$this->driver->toClose($paymentOrder);
    }
}
